<?php

/**
 * This is the model class for table "xyh_school".
 *
 * The followings are the available columns in table 'xyh_school':
 * @property string $id
 * @property string $name
 * @property string $prov_id
 * @property string $type_id
 * @property string $status
 */
class School extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return School the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xyh_school';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name,domain', 'length', 'max'=>255),
			array('prov_id, type_id', 'length', 'max'=>10),
			array('status', 'length', 'max'=>1),
                        array('initials', 'length', 'max'=>1),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, prov_id, type_id, status', 'safe', 'on'=>'search'),
                       
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                         'Area' => array(self::BELONGS_TO, 'Area', 'prov_id'),
                         'Type' => array(self::BELONGS_TO, 'Type', 'type_id'),
                         'Alumi' =>array(self::HAS_MANY,'Alumi','school_id'),
                         
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'prov_id' => 'Prov',
			'type_id' => 'Type',
			'status' => 'Status',
                        'initials' =>'首字母'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
                
               
		$criteria->compare('id',$this->id,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('prov_id',$this->prov_id,true);
		$criteria->compare('type_id',$this->type_id,true);
		$criteria->compare('status',$this->status,true);
                $criteria->compare('initials',$this->initials,true);
		return new CActiveDataProvider($this, array(
                         'sort' =>array('defaultOrder'=>'id DESC'),
			'criteria'=>$criteria,
		));
	}
}